package com.sykj.bsc.zjj.service.Impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sykj.bsc.rwl.po.SysMenu;
import com.sykj.bsc.rwl.po.Ztree;
import com.sykj.bsc.util.JsonUtils;
import com.sykj.bsc.zjj.bean.Bis_shop_post;
import com.sykj.bsc.zjj.mapper.Bis_shop_postMapper;
import com.sykj.bsc.zjj.mapper.Bis_shop_userMapper;
import com.sykj.bsc.zjj.service.Bis_shop_postService;

@Service
public class Bis_shop_postServiceImpl implements Bis_shop_postService {
	@Autowired
	private Bis_shop_postMapper bspm;
	@Autowired
	private Bis_shop_userMapper bsum;

	/**
	 * 查询所有
	 * Bis_shop_post
	 * 店铺职位信息表
	 */
	@Override
	public List<Map> selectBis_shop_post(Bis_shop_post bis_shop_post) {	
		
		return this.bspm.selectBis_shop_post(bis_shop_post);
	}
	
	/**
	 * 获取ID最大值
	 */
	@Override
	public String getId() {
		return this.bspm.getId();
	}

	/**
	 * 添加
	 * Bis_shop_post
	 * 店铺职位信息表
	 */
	@Override
	public void insertBis_shop_post(Bis_shop_post bis_shop_post,String userId) {
		this.bspm.insertBis_shop_post(bis_shop_post);
		bis_shop_post.setPost_id(bis_shop_post.getPost_id());
		String array=bis_shop_post.getArray();
		List<String> list=new ArrayList<>();
		String[] strings=array.split(",");
		for (int i = 0; i < strings.length; i++) {
			list.add(strings[i]);
		}
		bis_shop_post.setIds(list);
		//session
		bis_shop_post.setCreate_user_id(userId);
		bspm.insertBis_shop_menu(bis_shop_post);
	}

	/**
	 * 根据ID查询
	 * Bis_shop_post
	 * 店铺职位信息表
	 */
	@Override
	public Bis_shop_post findByIdBis_shop_post(String post_id) {
		return this.bspm.findByIdBis_shop_post(post_id);
	}

	/**
	 * 修改
	 * Bis_shop_post
	 * 店铺职位信息表
	 */
	@Override
	public void updateBis_shop_post(Bis_shop_post bis_shop_post,String userId) {
		this.bspm.updateBis_shop_post(bis_shop_post);
		//删除所有
		bspm.deletePost_menu(bis_shop_post.getPost_id());
		String array=bis_shop_post.getArray();
		List<String> list=new ArrayList<>();
		String[] strings=array.split(",");
		for (int i = 0; i < strings.length; i++) {
			list.add(strings[i]);
		}
		bis_shop_post.setIds(list);
		//session
		bis_shop_post.setCreate_user_id(userId);
		bspm.insertBis_shop_menu(bis_shop_post);
	}

	/**
	 * 删除
	 * 根据ID删除
	 * Bis_shop_post
	 * 店铺职位信息表
	 */
	@Override
	public void deleteBis_shop_post(String post_id) {
		this.bspm.deleteBis_shop_post(post_id);
	}
	
	/**
	 * 查询店铺职位信息表
	 * 判断职位编码是否重复
	 */
	@Override
	public Integer findByIdBis_shop_postpost_code(String post_code) {
		return this.bspm.findByIdBis_shop_postpost_code(post_code);
	}

	@Override
	public String checkPost_menu(String post_id) {
		List<SysMenu> list=bsum.selectShopMenu();
		List<Ztree> list2=new ArrayList<>();
		Ztree ztree=null;
		for (SysMenu s:list) {
			ztree=new Ztree();
			boolean bool=getcount(post_id, s.getMenu_id()+"");
			ztree.setChecked(bool);
			ztree.setOpen(bool);
			ztree.setId(s.getMenu_id());
			ztree.setpId(Integer.valueOf(s.getParent_id()));
			ztree.setName(s.getMenu_name());
			list2.add(ztree);
		}
		String json=JsonUtils.objectToJson(list2);
		return json;
	}

	@Override
	public boolean getcount(String post_id, String menu_id) {
		int count=bspm.getcount(post_id, menu_id);
		if(count>0)return true;
		return false;
	}
	
}
